package com.zyq.validation.service;

import com.zyq.validation.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindException;
import org.springframework.validation.Validator;

@Service
public class UserService1 {
    @Autowired
    private Validator validator;
    public boolean validateUserByValidator(User user){
        BindException bindException=new BindException(user, user.getUserName());
        //进行用户属性的验证
        validator.validate(user, bindException);
        return bindException.hasErrors();
    }

}
